var vue = new Vue({
    el:"#app",
    data:{
        tv:{destId:''},
        dests:{},
        content:''
    },
    filters:{
        dateFormat:function(date){
            return dateFormat(date, "YYYY-MM-DD")
        }
    },
    methods:{
        chosePic:function () {
            $("#coverBtn").click();
        },
        saveOrUpdate:function (state) {
            $("#state").val(state);
            console.log(state);
           /* id:
                state: 1
            title: 11
            coverUrl: https://wolf2w-wangsj.oss-cn-guangzhou.aliyuncs.com/f0d60c8b-9a10-4f2f-a724-547494f99daf.PNG
                travelTime: 2021-01-20
            person: 1
            ispublic: 1
            day: 11
            avgConsume: 11
            destId: 1
            summary: 11
            content: <p>11</p>*/
           var id = $('input[name=id]').val();
           var state = $('input[name=state]').val();
           var title = $('input[name=title]').val();
           var coverUrl = $('input[name=coverUrl]').val();
           var person = $('select[name=person]').val();
           var ispublic = $('input[name=ispublic]').val();
           var day = $('input[name=day]').val();
           var avgConsume = $('input[name=avgConsume]').val();
           var destId = $('#region').val();
           var summary = $('input[name=summary]').val();
           var content = $("#content").val(ck.getData());
           var travelTime = $('input[name=travelTime]').val();
            var param = $("#editForm").serialize()
            //var destId = $("#region").val();
            ajaxPost( "/travels/saveOrUpdate",
                {id:id,
                        state:state,
                        title:title,
                        coverUrl:coverUrl,
                        person:person,
                        ispublic:ispublic,
                        day:day,
                        avgConsume:avgConsume,
                        destId:destId,
                        summary:summary,
                        content:content
                },
                function (data) {
                //还缺一参数：目的地id
                var destId = $("#region").val();
                window.location.href = "/views/travel/detail.html?id=" + data.data + "&destId=" + destId;
            })
        }
    },
    mounted:function () {
        var id = getParams().id;
        //游记编辑
        /*ajaxGet("/travels/input",{id:id}, function (data) {
            var map = data.data;
            if(map.tv){//travel, 当id有值时需要进行回显
                vue.tv = map.tv;
                ue.setContent( map.tv.content);
            }
            vue.dests = map.dests;
        })*/

        ajaxGet("/destinations/list", {}, function (data) {
            vue.dests = data.data;
        })





        /*ajaxGet("/travels/detail", {id:id}, function (data) {
            vue.tv = data.data;
            ue.setContent( data.data.content);
        })*/


        //接口设计原则:一个接口一个功能
        // 查询目的:  destinations/list
        // 数据回显:  travels/detail?id=


    }
});

